﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CommunityToolkit.Mvvm.DependencyInjection;
using FanaticRock.Core.ServiceInterfaces;

namespace FanaticRock.Views.Music
{
    /// <summary>
    /// MusicHostView.xaml 的交互逻辑
    /// </summary>
    public partial class MusicHostView : UserControl
    {
        public MusicHostView()
        {
            InitializeComponent();

            var audioPlayService = Ioc.Default.GetService<IAudioPlayService>();
            audioPlayService.PlayStateChanged += AudioPlayService_PlayStateChanged;
        }

        private void AudioPlayService_PlayStateChanged(object? sender, Core.AudioPlay.Events.AudioPlayStateChangedEventArgs e)
        {
            //var pointer = PART_DiskPoint;
            var spinTo = 0d;
            switch (e.State)
            {
                case Core.AudioPlay.AudioPlayStateEnum.Playing:
                    spinTo = 33;
                    break;
                default:
                    spinTo = 0d;
                    break;
            }

            var anim = CreateSpinAnimation(spinTo);
            PART_RotationTransform.BeginAnimation(RotateTransform.AngleProperty, anim);
        }


        private DoubleAnimation CreateSpinAnimation(double to)
        {
            var dur = new Duration(TimeSpan.FromMilliseconds(300));
            var anim = new DoubleAnimation(to, dur);
            anim.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseOut };

            return anim;
        }
    }
}
